<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/9 0009
 * Time: 上午 11:40
 */

namespace App\Http\Classes;


class Cover extends Image
{
    private $dst900;
    private $dst300;
    private $dst100;
    private $url900;
    private $url300;
    private $url100;
    public function setDst()
    {
        // TODO: Implement setDst() method.
        $root = 'weiboimg/cover/';
        $this -> dst900 = $root.'cover_900/'.$this->name.$this->extension;
        $this -> dst300 = $root.'cover_300/'.$this->name.$this->extension;
        $this -> dst100 = $root.'cover_100/'.$this->name.$this->extension;
    }

    public function setUrl()
    {
        // TODO: Implement setUrl() method.
        $this -> url900 = $this -> host . $this -> dst900;
        $this -> url300 = $this -> host . $this -> dst300;
        $this -> url100 = $this -> host .$this -> dst100;
    }

    public function setOriginal()
    {
        // TODO: Implement setOriginal() method.
        $this -> original = 'weiboimg/cover/original/';
    }

    public function updateUser()
    {
        // TODO: Implement updateUser() method.
        $this -> setUrl();
        $user = new User($_COOKIE['user_id']);
        $user = $user->updateCover($this->url300,$this->url900,$this->url100);
        if($user){
            $this -> code = 200;
            $this -> msg = 'Head image saved and update success!';
        }
        else{
            $this -> code = 304;
            $this -> msg = 'Head image saved but update error!';
        }
    }

    public function getResult()
    {
        // TODO: Implement getResult() method.
        $data = [];
        $data['middle'] = $this -> url300;
        $data['big'] = $this -> url900;
        $data['small'] = $this -> url100;
        return $data;
    }

    public function howCrop($data, $src_img, $src_img_w, $src_img_h)
    {
        // TODO: Implement howCrop() method.
        $this -> croppedSize(920,300,$data,$this->dst900,$src_img,$src_img_w,$src_img_h);
        $this -> croppedSize(306,100,$data,$this->dst300,$src_img,$src_img_w,$src_img_h);
        $this -> croppedSize(100,33,$data,$this->dst100,$src_img,$src_img_w,$src_img_h);
    }
}